package com.cirkana.viewer.data.pic;

import java.io.DataInputStream;
import java.io.DataOutputStream;

import com.cirkana.data.pic.IPic;
import com.cirkana.serial.bin.BinarySerializationException;
import com.cirkana.serial.bin.BinarySerializationUtil;
import com.cirkana.serial.text.TextSerializationBuilder;
import com.cirkana.viewer.data.LocalDataRecord;

public class Pic extends LocalDataRecord implements IPic {

	protected static final String COLUMN_PIC_ID = "PIC_ID";
	protected static final String COLUMN_REMOTE_LOCATION = "REMOTE_LOCATION";
	protected static final String COLUMN_LOCAL_LOCATION = "LOCAL_LOCATION";
	protected static final String COLUMN_FORMAT = "FORMAT";
	protected static final String COLUMN_WIDTH = "WIDTH";
	protected static final String COLUMN_HEIGHT = "HEIGHT";

	@Override
	public Integer getId() {
		return getIntegerField(COLUMN_PIC_ID);
	}

	@Override
	public void setId(Integer id) {
		setIntegerField(COLUMN_PIC_ID, id);
	}

	@Override
	public Integer getFormat() {
		return getIntegerField(COLUMN_FORMAT);
	}

	@Override
	public Integer getHeight() {
		return getIntegerField(COLUMN_HEIGHT);
	}

	@Override
	public String getLocalLocation() {
		return getStringField(COLUMN_LOCAL_LOCATION);
	}

	@Override
	public String getRemoteLocation() {
		return getStringField(COLUMN_REMOTE_LOCATION);
	}

	@Override
	public Integer getWidth() {
		return getIntegerField(COLUMN_WIDTH);
	}

	@Override
	public void setFormat(Integer format) {
		setIntegerField(COLUMN_FORMAT, format);
	}

	@Override
	public void setHeight(Integer height) {
		setIntegerField(COLUMN_HEIGHT, height);
	}

	@Override
	public void setLocalLocation(String localLocation) {
		setStringField(COLUMN_LOCAL_LOCATION, localLocation);
	}

	@Override
	public void setRemoteLocation(String remoteLocation) {
		setStringField(COLUMN_REMOTE_LOCATION, remoteLocation);
	}

	@Override
	public void setWidth(Integer width) {
		setIntegerField(COLUMN_WIDTH, width);
	}

	@Override
	public void serialize(DataOutputStream out)
			throws BinarySerializationException {
		BinarySerializationUtil.serializeInteger(getId(), out);
		BinarySerializationUtil.serializeString(getRemoteLocation(), out);
		BinarySerializationUtil.serializeString(getLocalLocation(), out);
		BinarySerializationUtil.serializeInteger(getFormat(), out);
		BinarySerializationUtil.serializeInteger(getWidth(), out);
		BinarySerializationUtil.serializeInteger(getHeight(), out);
	}

	@Override
	public void deserialize(DataInputStream in)
			throws BinarySerializationException {
		setId(BinarySerializationUtil.deserializeInteger(in));
		setRemoteLocation(BinarySerializationUtil.deserializeString(in));
		setLocalLocation(BinarySerializationUtil.deserializeString(in));
		setFormat(BinarySerializationUtil.deserializeInteger(in));
		setWidth(BinarySerializationUtil.deserializeInteger(in));
		setHeight(BinarySerializationUtil.deserializeInteger(in));
	}

	@Override
	public String toText() {
		TextSerializationBuilder t = new TextSerializationBuilder();
		t.append("id", getId());
		t.append("remoteLocation", getRemoteLocation());
		t.append("localLocation", getLocalLocation());
		t.append("format", getFormat());
		t.append("width", getWidth());
		t.append("height", getHeight());
		return t.getTextSerialization();
	}
}
